package com.hall.items.msg;

import com.google.gson.Gson;
import erp.ERP;
import erp.process.definition.Process;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author zheng chengdong
 */
@Component
public class MsgSender {

    @Autowired
    private KafkaTemplate<String, String> template;

    private Gson gson = new Gson();

    public void sendProcess(boolean notSendForNullResult) {
        Process process = ERP.getProcess();
        if (process == null) {
            return;
        }
        if (notSendForNullResult && (process.getResult() == null)) {
            return;
        }
        String processJson = gson.toJson(process);
        template.send("process", processJson);
    }
}
